﻿// Study1107.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第十一章 流类库 输入流 read函数

#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

struct SalaryInfo
{
	unsigned id;
	double salary;
	
};
ostream& operator <<(ostream& out, const SalaryInfo& e)
{
	out << e.id << " " << e.salary << endl;
	return out;
}
int main()
{
	SalaryInfo empolyee1 = { 600001,8000 };
	ofstream os("payroll", ios_base::out | ios_base::binary);
	os.write(reinterpret_cast<char*>(&empolyee1), sizeof(empolyee1));
	os.close();

	ifstream is("payroll", ios_base::in | ios_base::binary);
	if (!is.is_open())
	{
		cout << "打开文件失败" << endl;
		return 0;
	}
	SalaryInfo empolyee2;
	is.read(reinterpret_cast<char*>(&empolyee2), sizeof(empolyee2));
	cout << empolyee2;
	is.close();
    return 0;
}

